<template>
	<view class="goods-item">
		<!-- 左边图片 -->
		<view class="goods-item-left">
			<radio :checked="goods.goods_state" color="#C00000" v-if="showRadio" @click="radioClickHandler"></radio>
			<image class="goods-image" :src="goods.goods_small_logo || defaultPic"></image>
		</view>
		<!-- 右边信息 -->
		<view class="goods-item-right">
			<view class="goods-name">
				{{goods.goods_name}}
			</view>
			<view class="goods-info-box">
				<view class="goods-price">
					{{tofixed}}
				</view>
				<uni-number-box :min="1" v-if="showNum" :value="goods.goods_count" @change="numChangeHandler"></uni-number-box>
			</view>

		</view>
	</view>

</template>

<script>
	export default {
		name: "my-goods",
		data() {
			return {
				// 默认的空图片
				defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
			};
		},
		props: {
			goods: {
				type: Object,
				default: () => ({})
			},
			showRadio: {
				type: Boolean,
				default: false
			},
			showNum: {
				type: Boolean,
				default: false
			}
		},
		computed: {
			tofixed() {
				return '¥' + Number(this.goods.goods_price).toFixed(2)
			}
		},
		methods: {
			radioClickHandler() {
				// 调用父组件绑定的函数
				this.$emit('radio-change', {
					goods_id: this.goods.goods_id,
					goods_state: !this.goods.goods_state
				})
			},
			numChangeHandler(value) {
				console.log(typeof value)
				this.$emit('num-change', {
					goods_id: this.goods.goods_id,
					goods_count: value,
					// goods_count: parseInt(value)
				})
			}
		}
	}
</script>

<style lang="scss">
	.goods-item {
		display: flex;
		border-bottom: 1px solid #efefef;
		padding: 8rpx;

		.goods-item-left {
			display: flex;
			align-items: center;
			// border: 1px solid blue;
			// flex: 2;

			.goods-image {
				width: 200rpx;
				height: 200rpx;
				vertical-align: middle;
				// display: block;
			}
		}

		.goods-item-right {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			flex: 1;
			// width: 100%;
			// border: 1px solid red;

			.goods-name {
				font-size: 24rpx;
			}

			.goods-info-box {
				display: flex;
				justify-content: space-between;
			}

			.goods-price {
				font-size: 32rpx;
				color: #c00000;
			}
		}
	}
</style>